<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<jsp:include page="../frame/header.jsp"></jsp:include>

<title>添加或编辑论坛分区</title>
<style>
#picture {
	position: absolute;
	left: 600px;
	top: 180px;
}
</style>

</head>

<body>
	<div class="container-fluid">
		<div class="row-fluid">
			<div>
				<ul class="breadcrumb">
					<li><a href="#">娱乐交友</a> <span class="divider">/</span></li>
					<li><a href="#">曼大BBS</a></li>
				</ul>
			</div>

			<div class="box">
				<div class="box-header well" data-original-title>
					<h2>
						<c:choose>
							<c:when test="${forum.forumId == 0 }">
								添加论坛分区
							</c:when>
							<c:when test="${forum.forumId > 0 }">
								编辑论坛分区 - 【${forum.name }】
							</c:when>
						</c:choose>
					</h2>
					<div class="box-icon">
						<a href="#" class="btn btn-setting btn-round"><i
							class="icon-cog"></i></a> <a href="#"
							class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						<a href="#" class="btn btn-close btn-round"><i
							class="icon-remove"></i></a>
					</div>
				</div>
				<div class="box-content">
					<form id="myform" class="form-horizontal" method="post"
						action="<c:url value="/admin/forum/forum" />">
						<fieldset>
							<input type="hidden" name="forumId" value="${forum.forumId }">
							<input type="hidden" name="type" value="${forum.type }">
							<div class="control-group">
								<label class="control-label" for="name">分区名称</label>
								<div class="controls">
									<input class="input-xlarge" id="name" name="name" type="text"
										value="${forum.name }" maxlength="50" check-type="required"
										required-message="请输入分区名称">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="displayOrder">显示顺序</label>
								<div class="controls">
									<input class="input-xlarge" id="displayOrder"
										name="displayOrder" type="text" value="${forum.displayOrder }">
								</div>
							</div>
							
							<div class="control-group">
								<label class="control-label" for="status">显示分区</label>
								<div class="controls">
									<label class="radio inline">
									  <input type="radio" name="status" id="optionsRadios1" value="1"
									   <c:if test="${forum.status == 1}">checked</c:if> >
										  是
									</label>
									<label class="radio inline">
									  <input type="radio" name="status" id="optionsRadios2" 
									   value="0" <c:if test="${forum.status == 0}">checked</c:if> >
									  	否
									</label>
								</div>
							</div>

							<div class="control-group">
								<label class="control-label" for="fileInput">分区图标</label>
								<div class="controls">
									<input class="input-file uniform_on" name="file"
										id="userHeader" type="file"> <input type="button"
										class="btn btn-success" value="upload"
										onclick="return ajaxFileUpload();">
								</div>
								<img id="loading" class="hide"
									src="<c:url value="/resources/img/ajax-loader-6.gif"/>">
								<img id="picture" src='${forum.forumImg }' width="100"
									height="100"> <input type="hidden" name="forumImg"
									id="forumImg" value="${forum.forumImg }">
							</div>

							<div class="control-group">
								<label class="control-label" for="description_mc">分区描述 </label>
								<div class="controls">
									<textarea rows="6" id="description_mc" name="description_mc"
										class="input-xxlarge">${forum.description_mc }</textarea>
								</div>
							</div>
							<div class="form-actions">
								<button id="saveBtn" type="button" class="btn btn-primary">保存</button>
								<button id="cancelBtn" type="button" class="btn">返回</button>
							</div>
						</fieldset>
					</form>

				</div>
			</div>
			<!--/span-->

		</div>
	</div>
	<!--/row-->
</body>

<jsp:include page="../frame/scripts.jsp"></jsp:include>
<script type="text/javascript">
	$(document).ready(function() {

		$("#myform").validation();

		//返回上一页
		$('#cancelBtn').click(function() {
			window.location.href = '<c:url value="/admin/forum/forum" />';
		});

		//保存
		$('#saveBtn').click(function() {
			$("#myform").submit();
		})

	})

	//上传图片
	function ajaxFileUpload() {

		$("#loading").ajaxStart(function() {
			//开始上传文件时显示一个图片
			$(this).show();
		}).ajaxComplete(function() {
			//文件上传完成将图片隐藏起来
			$(this).hide();
		});

		$.ajaxFileUpload({
			url : '<c:url value="/fileupload"/>',//用于文件上传的服务器端请求地址
			secureuri : false,//一般设置为false
			fileElementId : 'userHeader',//文件上传空间的id属性  <input type="file" id="file" name="file" />
			dataType : 'JSON',//返回值类型 一般设置为json(大写)
			success : function(data, status) {
				var image = DOMAIN + '/resources/fileupload/' + $(data).html();
				$("#picture").attr('src', image).show();
				$("input[name='forumImg']").val(image);
			},
			error : function(data, status, e) {
				alert(e);
			}
		})

		return false;
	}
</script>